<template>
  <div class="dashboard-container">
    {{name}}
  </div>
</template>

<script>
import { setToken, setUser, setPermissionMenu } from '@/utils/auth'
import { resetRouter } from '@/router'
import { mapGetters } from 'vuex'

export default {
  name: 'Dashboard',
  data() {
    return {
      name: '',
    }
  },
  created() {
    var that = this
    var code = this.$route.query.code
    that.$system
      .get('auth/gitee/signin-callback?code=' + code)
      .then((res) => {
        setToken(res.token)
        setUser(res.user)
        that.getMenuPermission(res.user.roleId)
      })
      .catch(() => {})
      .finally(() => {})
  },
  methods: {
    getMenuPermission(roleId) {
      let that = this
      that.$system
        .get('menu/GetMenuByRoleId', { id: roleId })
        .then((res) => {
          setPermissionMenu(res)
          resetRouter()
          that.$router.push({ path: that.redirect || '/' })
        })
        .catch((res) => {})
        .finally(() => {})
    },
  },
  computed: {
    ...mapGetters(['user']),
  },
}
</script>

<style lang="scss" scoped>
.dashboard {
  &-container {
    margin: 30px;
  }
  &-text {
    font-size: 30px;
    line-height: 46px;
  }
}
</style>
